package com.chinawayltd.ews.sample.core.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.chinawayltd.ews.sample.core.interceptor.WebTokenInterceptor;

/**
 *web拦截器配置类
 */
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
	
	@Value("${sys.isOpenFilter}")
	private Boolean isOpenFilter = false;
	
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    	if(isOpenFilter){
    		 //拦截所有web请求进行token是否有效验证
    		registry.addInterceptor(webTokenInterceptor())
    			.addPathPatterns("/web/**")
    			.excludePathPatterns("/web/**/readExcel");
    	}
        super.addInterceptors(registry);
    }

    @Bean
    public WebTokenInterceptor webTokenInterceptor() {
        return new WebTokenInterceptor();
    }

}
